//
//  BMHAboutMeController.m
//  BMHVideoMain
//
//  Created by 陈宪栋 on 2017/4/6.
//  Copyright © 2017年 Baomihua. All rights reserved.
//

#import "BMHAboutMeController.h"
#import <UtilsMacro.h>
#import <Masonry.h>
//#import "BMHAPIManager.h"

@interface BMHAboutMeController ()///<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, copy) NSString *appName;
@property (nonatomic, copy) NSString *appVersion;

@property (nonatomic,strong)UIImageView *logoImageView;
@property (nonatomic,strong)UILabel *appNameLabel;
@property (nonatomic,strong)UILabel *appVersionLabel;
@property (nonatomic,strong)UILabel *copyrightLabel;

@property (nonatomic, strong) UISwitch *sw;
@end

@implementation BMHAboutMeController

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //self.currentPageId = @"aboutme";
    [self showBackButton:NULL];
    self.navigationItem.title = @"关于我们";
    [self setupView];
    [self setupData];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
//    [[[BMHAPIManager sharedStatManager] gatherCurrentPageId:self.currentPageId previousPageId:self.previousPageId videoId:nil] subscribeNext:^(id x) {
//        NSLog(@"%@", x);
//    } error:^(NSError *error) {
//        NSLog(@"%@", error);
//    }];
    
    //[BMHStatisticsTool beginLogPageView:@"关于我们页面"];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
   // [BMHStatisticsTool endLogPageView:@"关于我们页面"];
}

- (void)setupView {
    /*
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView.separatorColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
     */
    self.logoImageView = [[UIImageView alloc]init];
    self.logoImageView.userInteractionEnabled = YES;
    ViewRadius(self.logoImageView, 10);
    _logoImageView.image = [UIImage imageNamed:@"xiangLove"];
    [self.view addSubview:_logoImageView];
    [_logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.centerY.equalTo(self.view.mas_centerY).with.offset(-50);
        make.size.mas_equalTo(CGSizeMake(70, 70));
    }];
    
//    if (release_channel == 0) {
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(action:)];
//        tap.numberOfTapsRequired = 3;
//        [self.logoImageView addGestureRecognizer:tap];
//    }
    
    self.appNameLabel = [[UILabel alloc]init];
    _appNameLabel.font = [UIFont systemFontOfSize:14.0];
    _appNameLabel.textColor = [UIColor darkGrayColor];
    _appNameLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_appNameLabel];
    [_appNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.equalTo(self.logoImageView.mas_bottom).with.offset(15);
        make.height.mas_equalTo(@20);
    }];
    
    self.appVersionLabel = [[UILabel alloc]init];
    _appVersionLabel.font = [UIFont systemFontOfSize:14.0];
    _appVersionLabel.textColor = [UIColor darkGrayColor];
    _appVersionLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_appVersionLabel];
    [_appVersionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.equalTo(self.appNameLabel.mas_bottom).with.offset(10);
        make.height.mas_equalTo(@20);
    }];
    
    /*
    self.copyrightLabel = [[UILabel alloc]init];
    _copyrightLabel.font = [UIFont systemFontOfSize:13.0];
    _copyrightLabel.textColor = [UIColor whiteColor];
    _copyrightLabel.textAlignment = NSTextAlignmentCenter;
    _copyrightLabel.text = @"Copyright©2016 爆米花 baomihua.com 版权所有";
    [self.view addSubview:_copyrightLabel];
    [_copyrightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.bottom.equalTo(self.view.mas_bottom).with.offset(-20);
        make.height.mas_equalTo(@20);
    }];
    */
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
}

- (void)setupData {
    self.appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
    self.appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    self.appNameLabel.text = self.appName;
    self.appVersionLabel.text = [NSString stringWithFormat:@"v%@", self.appVersion];
   //[self.tableView reloadData];
}

- (void)action:(UITapGestureRecognizer *)tap {
    if (_sw == nil) {
        _sw = [[UISwitch alloc] init];
        [_sw addTarget:self action:@selector(swAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_sw];
        [_sw mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(60, 30));
            make.top.equalTo(self.appVersionLabel.mas_bottom).offset(20);
            make.centerX.equalTo(self.view);
        }];
        _sw.on = [[UserDefaults objectForKey:BMHIsTest] boolValue];
    }
}

- (void)swAction:(id)sender {
    if (_sw.on) {
        [UserDefaults setObject:@(YES) forKey:BMHIsTest];
        [MBProgressHUD showContent:@"已改为测试接口，请返回刷新"];
    } else {
        [UserDefaults setObject:@(NO) forKey:BMHIsTest];
        [MBProgressHUD showContent:@"已改为正式接口，请返回刷新"];
    }
    [UserDefaults synchronize];
}

/*
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    }
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.textLabel.text = self.appName;
    cell.detailTextLabel.font = [UIFont systemFontOfSize:13];
    cell.detailTextLabel.text = [NSString stringWithFormat:@"v%@", self.appVersion];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
 */
@end
